﻿using System.ComponentModel.Composition;
using SS.Net.AppGen.Utils;

namespace SS.Net.AppGen.WebGenerators.WebControllerGenerator
{
    /// <summary>
    /// The class is reponsible for generating common partial controller
    /// </summary>
    [Export(typeof(PartialControllerCommonGenerator))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class PartialControllerCommonGenerator : PartialControllerGenerator
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public PartialControllerCommonGenerator()
        {
            // Start to deserialize xml template file
            this.XMLTemplate = "PartialControllerCommonTemplate.xml";
            this.DeserializeTemplate();
            this.UpdateAlgorithm();
        }

        /// <summary>
        /// Initialize the algorithms for Delete, Update, Insert Item
        /// </summary>
        private void UpdateAlgorithm()
        {
            this._deleteAlgorithm = IoC.Get<DeleteControllerItemByCommonAlgorithm>();
            this._updateAlgorithm = IoC.Get<UpdateControllerItemByCommonAlgorithm>();
            this._insertAlgorithm = IoC.Get<InsertControllerItemByCommonAlgorithm>();
        }
    }
}
